var root_path = getRootPath_web();

function predictLeftTime(lineId, stopId) {
    var locationData = getLocation();
    var longitude = locationData.lng;
    var latitude = locationData.lat;
    var velocity = locationData.speed;

    // var weather = getWeather();

    var weather_temperature = today_weather.data.temperature;
    var weather_info = today_weather.data.info;

    // console.log(weather_temperature, weather_info);

    var data = {
        "device_id" : lineId,
        "predicted_stop_id" : stopId,
        "longitude" : longitude,
        "latitude" : latitude,
        "velocity" : velocity,
        "weather_temperature" : weather_temperature,
        "weather_info" : weather_info
    }

    var predicted_time;
    var apiUrl = root_path + "/getPredictedTimeServlet.do";
    $.ajax({
        url: apiUrl,
        type: "GET",
        cache: false,
        dataType: 'json',
        async: false,
        data: data,
        success:function (result){
            console.log("success");
            // console.log(result);
            predicted_time = result.data;
        }
    })
    predicted_time = parseInt(predicted_time)

    return predicted_time;
}

function getLocation(){
    // 返回通勤车当前位置信息（作为预测模型的输入数据）
    var apiUrl = root_path + "/getLocation.do";
    var data;
    // console.log(apiUrl);
    $.ajax({
        url: apiUrl,
        type: "GET",
        cache: false,
        dataType: 'json',
        async: false,
        success: function (result) {
            // console.log("currentCarId="+lineId);
            for (let i = 0; i < result.data.length; i++) {
                if (result.data[i].lineId === currentLineId) {
                    data = result.data[i];//路线1
                    break;
                }
            }
        },
        error: function () {
            console.log("Connect Failed");
        }
    });
    // console.log(data);
    return data;
}